package com.hamster.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hamster.crm.pojo.CourseTask;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Tarry
 * @create 2019/12/19 14:46
 */
@Repository
@Mapper
public interface CourseTaskMapper extends BaseMapper<CourseTask> {
    /**
     * 根据id删除【删除标记设为1】
     * @param id
     */
    @Update("update course_task set del = 1 where id = #{id}")
    void deleteTag(String id);

    /**
     * 根据id修改状态为“已下发”
     * @param id
     */
    @Update("update course_task set state = #{state} where id = #{id}")
    void updateCourseTaskStateById(@Param("id") String id,@Param("state") String state);

    /**
     * 查询参课任务列表
     */
    @Select("select * from course_task where del = 0")
    @Results({
            @Result(property = "id",column = "id",id = true),
            @Result(property = "startTime",column = "start_time"),
            @Result(property = "endTime",column = "end_time"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "course",column = "course"),
            @Result(property = "state",column = "state",one = @One(select = "com.hamster.crm.mapper.CourseTaskMapper.queryState"))
    })
    List<CourseTask> queryList();

    @Select("select state from dictionary_state where id = #{id}")
    String queryState(String id);
}
